package com.wsoft.hr.pm.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.hr.pm.entity.HrPmScopeEntity;
import com.wsoft.hr.pm.query.scope.ScopeInsertQuery;
import com.wsoft.hr.pm.query.scope.ScopeListQuery;
import com.wsoft.hr.pm.query.scope.ScopeUpdateQuery;
import com.wsoft.hr.pm.service.IHrPmScopeService;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 维度表 前端控制器
 * @author Z001
 * @since 2025年02月24日 11:18:27
 */
@RestController
@Tag(name = "维度")
@RequestMapping("/hr/pm/scope")
public class HrPmScopeController {

    @Resource
    private IHrPmScopeService scopeService;

    @Operation(summary = "新增维度", description = "新增维度")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ScopeInsertQuery query) {
        boolean b = scopeService.insertScope(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑维度", description = "编辑维度")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ScopeUpdateQuery query) {
        boolean b = scopeService.updateScope(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "维度详情", description = "维度详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(scopeService.getScopeInfo(id));
    }


    @Operation(summary = "删除维度", description = "删除维度")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = scopeService.delete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "维度分页", description = "维度分页")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ScopeListQuery query) {
        PageInfo<HrPmScopeEntity> page = scopeService.listScope(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }

}
